﻿function editPassword(username) {
	if (refreshWin('editPassword_' + username)) return;

	var txtusername = new Ext.form.TextField({
				fieldLabel : '用户名',
				minLength : 5,
				maxLength : 20,
				value : username
			});
	var passwordOld = new Ext.form.TextField({
				fieldLabel : '原密码',
				minLength : 5,
				maxLength : 20,
				inputType : 'password'
			});
	var password = new Ext.form.TextField({
				fieldLabel : '新密码',
				minLength : 5,
				maxLength : 20,
				inputType : 'password'
			});
	var passwordB = new Ext.form.TextField({
				fieldLabel : '确认新密码',
				minLength : 5,
				maxLength : 20,
				inputType : 'password',
				validator : function(v) {
					if (Ext.isEmpty(v) || password.getValue() == v) return true;
					return '两次密码输入不一致';
				}
			});

	var toolbar = new Ext.Toolbar({
				items : [new Ext.Button({
									text : '取消',
									iconCls : 'cancel-icon',
									handler : function() {
										win.close();
									}
								}), new Ext.Button({
									text : '更改',
									iconCls : 'ok-icon',
									handler : onsubmit
								})]
			});
	var form = new Ext.FormPanel({
				frame : true,
				labelAlign : 'right',
				labelWidth : 70,
				defaults : {
					anchor : '95%',
					allowBlank : false
				},
				items : [sys.god ? txtusername : {}, sys.god ? {} : passwordOld, password,
						passwordB],
				fbar : toolbar
			});
	var win = new Ext.Window({
				id : 'editPassword_' + username,
				title : '更改密码' + (sys.god ? ' - ' + username : ''),
				iconCls : 'password-icon',				width : 300,
				minWidth : 250,
				autoHeight : true,
				items : form
			});
	win.show();
	passwordOld.focus(true, 200);

	function onsubmit() {
		if (!form.getForm().isValid()) {
			alertx('请正确输入内容！');
			return;
		}
		editUserPassword({
					username : txtusername.getValue(),
					oldPassword : passwordOld.getValue(),
					password : password.getValue(),
					success : function() {
						alertx('密码更改成功！');
						win.close();
					}
				});
	}
}

function editUserPassword(obj) {
	ajax({
				url : url.editUserPassword,
				params : {
					username : obj.username,
					oldPassword : obj.oldPassword,
					password : obj.password
				},
				success : obj.success
			});
}
